#include "NBTTagBase.h"

const NBTTagBase *NBTTagBase::Find(const std::string &name) const
{
	if (name.find_first_of('.') != std::string::npos)
	{
		std::queue<std::string> nodes(String::Split<std::deque<std::string>>(name, ".", false));
			
		const NBTTagBase *node;
		for (node = this; nodes.size() != 0 && node != nullptr; node = node->Find(popAndReturn(nodes))) ;

		return node;
	}
	else
	{
		auto compound = As<NBTTagCompound>()->Value;

		for (auto it = compound.begin(); it != compound.end(); ++it)
		{
			auto &c = (*it);

			if (c->Name == name)
				return c;
		}
	}

	return nullptr;
}